package poi.SurpriseCalculator;

import java.util.ArrayList;
import java.util.HashMap;

import agent.Context.Goal;

import masterAgent.DBmanager.DBConnection;

import poi.Info.POI;
import poi.Surprise.SurpriseDaysOff;
import poi.Surprise.SurprisePrice;
import poi.Surprise.SurpriseSchedule;

/**
 * This class is used to calculate the Master agent Surprise for the all the
 * parameters DayOff, Price and Schedule
 * 
 * @author Hernani Costa
 * @version 0.1 date: 29/11/2012
 */
public class SurpriseCalculatorForPOI {

	SurpriseCalculatorForSchedule schedule;
	HashMap<Integer, SurpriseSchedule> poiSurpriseSchedule;
	SurpriseCalculatorForDaysOff daysOff;
	HashMap<Integer, SurpriseDaysOff> poiSurpriseDayOff;
	SurpriseCalculatorForPrice price;
	HashMap<Integer, SurprisePrice> poiSurprisePrice;

	/**
	 * ------------------------------------------------------------------------
	 * Constructor class
	 * ------------------------------------------------------------------------
	 * 
	 * @param pois - list with the POIs that we intend to calculate the surprise
	 */
	public SurpriseCalculatorForPOI(HashMap<Integer,POI> pois) {
		schedule = new SurpriseCalculatorForSchedule(pois);
		poiSurpriseSchedule = schedule.getPoiSurpriseSchedule();
		daysOff = new SurpriseCalculatorForDaysOff(pois);
		poiSurpriseDayOff = daysOff.getPoiSurpriseDayOff();
		price = new SurpriseCalculatorForPrice(pois);
		poiSurprisePrice = price.getPoiSurprisePrice();
	}

	// ------------------------------------------------------------------------
	// ------------------------GETs and SETs-----------------------------------
	// ------------------------------------------------------------------------

	public HashMap<Integer, SurpriseSchedule> getPoiSurpriseSchedule() {
		return poiSurpriseSchedule;
	}

	public HashMap<Integer, SurpriseDaysOff> getPoiSurpriseDayOff() {
		return poiSurpriseDayOff;
	}

	public HashMap<Integer, SurprisePrice> getPoiSurprisePrice() {
		return poiSurprisePrice;
	}

	public String to_String() {
		String info = "";
		for (int poiID : poiSurpriseDayOff.keySet()) {
			info += "poiID: " + poiID + "\n";
			info += "\t" + poiSurpriseDayOff.get(poiID).to_String() + "\n";
			info += "\t" + poiSurpriseSchedule.get(poiID).to_String() + "\n";
			info += "\t" + poiSurprisePrice.get(poiID).to_String() + "\n";
		}
		return info;
	}

	/**
	 * ------------------------------------------------------------------------
	 * Only for debug purpose
	 * ------------------------------------------------------------------------
	 */
	public static void main(String args[]) {
		// DBManager manager = new DBManager();
		DBConnection connector = new DBConnection();

		POI poi = connector.getPOI(1507669);
		// System.err.println("O pesquisado\n" + poi.to_String() + "\n\n");

		HashMap<Integer,POI> pois = connector.getPOIsNearLocation(poi.getLocation(),
				200, new Goal().getCoffee());
		// for (POI p : pois) {
		// System.err.println(p.to_String());
		// }

		SurpriseCalculatorForPOI m = new SurpriseCalculatorForPOI(pois);
		System.out.println(m.to_String());
	}

}
